const getDefaultState = () => {};

const state = getDefaultState();

const mutations = {};

const actions = {
  //去除对象中的空属性
  async removeEntityObj({ state }, obj) {
    return new Promise((resolve, reject) => {
      try {
        newObj = Object.fromEntries(
          Object.entries(obj).filter(
            ([key, value]) =>
              value !== null &&
              value !== undefined &&
              Object.keys(value).length !== 0
          )
        );
        resolve(newObj);
      } catch (err) {
        reject(err);
      }
    });
  },
  //数组去重
  async arrayDeduplication({ state }, arr) {
    return new Promise((resolve, reject) => {
      try {
        var newArr = arr.filter((item, index, arr) => {
          return arr.indexOf(item, 0) == index;
        });
        resolve(newArr);
      } catch (err) {
        reject(err);
      }
    });
  },
  //求交集
  async findTheIntersection({ state }, arr1, arr2) {
    return new Promise((resolve, reject) => {
      try {
        var com = arr1.filter(v => {
          return arr2.includes(v);
        });
        resolve(com);
      } catch (err) {
        reject(com);
      }
    });
  }
};

export default {
  namespaced: true,
  state,
  mutations,
  actions
};
